package setting

import (
	"fmt"
	"github.com/starmotioncf/common/setting"
	"sync"
)

var settingsList []*setting.Category
var settingsMap map[string]*setting.FieldMeta
var initOnce sync.Once

func init() {
	initOnce.Do(func() {
		settingsList = setting.GetCategories(&Settings{})
		settingsMap = make(map[string]*setting.FieldMeta, 0)
		for i := range settingsList {
			for j := range settingsList[i].Fields {
				settingsMap[fmt.Sprintf("%s.%s", settingsList[i].Name, settingsList[i].Fields[j].Name)] = settingsList[i].Fields[j]
			}
		}
	})
}

func GetCategories() []*setting.Category {
	return settingsList
}

func GetSettingFieldMeta(key string) *setting.FieldMeta {
	return settingsMap[key]
}

func GetSettingFieldMetaMaps() map[string]*setting.FieldMeta {
	return settingsMap
}
